package org.metasketch.editor.toolbox;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javafx.scene.control.ToolBar;

import org.metasketch.graphics.Diagram;

public class DiagramTypeManager {

	List<String> names = new ArrayList<String>();
	List<IDiagramType> diagramTypes = new ArrayList<IDiagramType>();
	Map<String, IDiagramType> diagramTypePerName = new HashMap<String, IDiagramType>();

	public void register(IDiagramType type) {
		String name = type.getName();
		if (names.contains(name))
			throw new RuntimeException("Duplicated Diagram Type " + name);

		diagramTypes.add(type);
		names.add(name);
		diagramTypePerName.put(name, type);
	}

	public IDiagramType getDiagramType(String name) {
		return diagramTypePerName.get(name);
	}

	public Diagram createDiagram(String name) {
		return diagramTypePerName.get(name).create();
	}

	public ToolBar getToolbox(String name) {
		return diagramTypePerName.get(name).getToolbar();
	}

	public List<String> getNames() {
		return names;
	}

}
